<template>
	<view class="gui-padding">
		<view class="gui-margin-top-large"></view>
		<form @submit="submit">
			<view v-if="weekday_list!=''">
				<text class="gui-h6 gui-color-gray gui-bold">工作日价格设置（价格单位：元）</text>
			</view>

			<view class="gui-form-item gui-border-b" v-if="weekday_list!=''" v-for="(item,index) in weekday_list"
				:key="index">
				<text class="gui-form-label" style="width: 180rpx;">{{item.title}}</text>
				<view class="gui-form-body">
					<input type="number" class="gui-form-input" placeholder="请输入价格" v-model="item.money" />
				</view>
			</view>


			<view class="gui-margin-top" v-if="weekend_list!=''">
				<text class="gui-h6 gui-color-gray gui-bold">周末价格设置（价格单位：元）</text>
			</view>

			<view class="gui-form-item gui-border-b" v-if="weekend_list!=''" v-for="(item,index) in weekend_list"
				:key="index">
				<text class="gui-form-label" style="width: 180rpx;">{{item.title}}</text>
				<view class="gui-form-body">
					<input type="number" class="gui-form-input" placeholder="请输入价格" v-model="item.money" />
				</view>
			</view>


			<view class="gui-margin-top-large gui-flex gui-rows gui-nowrap gui-justify-content-end">
				<button type="default" class="gui-button gui-bg-blue" style="width:200rpx;" formType="submit">
					<text class="gui-icons gui-color-white gui-button-text">提交</text>
				</button>
			</view>
			<view style="height:80rpx;"></view>
		</form>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				weekday_list: "",
				weekend_list: "",
				weekday_money: 0,
				weekend_money: 0,
			}
		},
		onLoad: function(query) {
			this.$globalMethod();
			this.get_user_paiban_list();
		},
		methods: {
			get_user_paiban_list() {
				let _this = this;
				_this.graceJS.get(_this.serverUrl + '/api.teacher/get_user_paiban_list', {

					}, {
						token: _this.token
					}, (res) => {
						if (res.code == 0) {
							_this.weekday_list = res.data.weekday_arr;
							_this.weekend_list = res.data.weekend_arr;
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'error'
							})
						}
					},
					(e) => {
						uni.showToast({
							title: '网络请求错误，请稍后重试',
							icon: 'error'
						})
					})
			},
			// 表单提交
			submit: function(e) {
				let _this = this;
				// 部分能够获得的表单数据 在 e 对象保存
				// 不支持表单直接获取的数据通过事件记录
				// 最终整理获得完整的表单记录
				e.preventDefault();
				// var fromData   = e.detail.value;
				var weekday_values = this.weekday_list.map(item => item);

				for (var i = 0; i < weekday_values.length; i++) {
					if (weekday_values[i].money == '') {
						uni.showToast({
							title: '请输入' + weekday_values[i].title + '的价格',
							icon: 'none'
						});

						return;
					}
				}

				var weekend_values = this.weekend_list.map(item => item);

				for (var i = 0; i < weekend_values.length; i++) {
					if (weekend_values[i].money == '') {
						uni.showToast({
							title: '请输入' + weekend_values[i].title + '的价格',
							icon: 'none'
						});

						return;
					}
				}


				uni.showLoading({
					title:'加载中'
				})

				_this.graceJS.post(_this.serverUrl + '/api.teacher/set_paiban_money', {
						weekday_list: weekday_values,
						weekend_list: weekend_values,
					}, 'json', {
						token: _this.token
					}, (res) => {
						
						uni.hideLoading();
						
						if (res.code == 0) {
							uni.navigateTo({
								url: '/pages/my/player_index',
								success: function() {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									})
								}
							})
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'error'
							})
						}
					},
					(e) => {
						uni.hideLoading();
						uni.showToast({
							title: '网络请求错误，请稍后重试',
							icon: 'error'
						})
					})





			}
		}
	}
</script>
<style scoped>
	.gui-text-small {
		line-height: 50rpx;
	}
</style>